import React from 'react';
import {PageContainer} from '@ant-design/pro-layout';
import {Button, Space, Table, TreeSelect, Switch, message} from 'antd';
import type {ProColumns} from '@ant-design/pro-table';
import ProTable, {TableDropdown} from '@ant-design/pro-table';
import {PlusOutlined} from '@ant-design/icons';
import {getExpressLists} from "@/services/ant-design-pro/express";
import {history} from 'umi';


const Logistics = () => {
  const columns: ProColumns = [
    {
      title: 'ID',
      dataIndex: 'id',
      search: false,
      align: 'center',
      width: 100,
    },
    {
      title: '物流公司名称',
      dataIndex: 'title',
      search: false,
      align: 'center',
      width: 200,
    },
    {
      title: '编码',
      dataIndex: 'code',
      search: false,
      align: 'center',
      width: 100,
    },
    {
      title: '搜索',
      dataIndex: 'search',
      search: true,
      hideInTable: true,
      renderFormItem: (_, {defaultRender}) => {
        return defaultRender(_);
      },
    },
    {
      title: '排序',
      dataIndex: 'sort',
      align: 'center',
      search: false,
      width: 100,
      sorter: (a, b) => a.containers - b.containers,
    },
    {
      title: '是否显示',
      dataIndex: 'is_show',
      filters: true,
      onFilter: true,
      search: false,
      align: 'center',
      valueType: 'select',
      width: 100,
      render: (_, record) =>
        <Switch
          checkedChildren="显示"
          unCheckedChildren="隐藏"
          defaultChecked={record.state === 0}
          // onChange={async () => {
          //   const response = await setGoodsPutAway(record.id)
          //   if (response.status === undefined) {
          //     message.success('操作成功')
          //   } else {
          //     message.error('操作失败')
          //   }
          // }
          // }
        />
    },
    {
      title: '操作',
      valueType: 'option',
      align: 'center',
      render: (text, record, _, action) => [
        <a
          key="editable"
          onClick={() => history.push('/manageGoods/editGoods/3433')}
        >
          编辑
        </a>,
        <a href={record.url} target="_blank" rel="noopener noreferrer" key="view">
          查看
        </a>,
        <TableDropdown
          key="actionGroup"
          onSelect={() => action?.reload()}
          menus={[
            {key: 'copy', name: '复制'},
            {key: 'delete', name: '删除'},
          ]}
        />,
      ],
    },
  ];

  /*
  * 获取物流公司信息
  * */

  // const getData = async (params) => {
  //   const data = await getExpressLists(params)
  //   console.log(data)
  // }

  return (
    <div>
      <PageContainer
        header={{
          title: '物流公司',
          breadcrumb: {},
        }}
      >
        <ProTable
          columns={columns}
          // request={async (params= {}) => {
          //
          //   return getData(params);
          //   console.log(getData())
          // }}
          request={async ()=>{
           return getExpressLists()
          }}
          editable={{
            type: 'multiple',
          }}
          rowKey="id"
          search={{
            labelWidth: 'auto',
          }}
          pagination={{
            pageSize: 10,
          }}
          dateFormatter="string"
          // headerTitle=""
          headerTitle={
            <Button key="button" icon={<PlusOutlined/>} type="primary"
              // onClick={() => history.push('/manageGoods/addGoods')}
            >
              同步物流公司
            </Button>
          }
        />
      </PageContainer>
    </div>
  );
}

export default Logistics;
